

class Animal {
    public String name;
    public int age;

    public void eat() {
        System.out.println(this.name+"正在吃！");
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }

    public void bark() {
        System.out.println(this.name+"汪汪叫！");
    }

    @Override
    public void eat() {
        System.out.println(this.name+"正在吃狗粮！");
    }
}

class Bird extends Animal {
    public Bird(String name, int age) {
        super(name, age);
    }

    public void Sing() {
        System.out.println(this.name+"渣渣叫！");
    }

    public void fly() {
        System.out.println(this.name+"正在飞！");
    }

    @Override
    public void eat() {
        System.out.println(this.name+"正在吃鸟食!");
    }
}



public class Test {



    public static Animal func2() {
        return new Dog("xiaohuang",100);
    }

    public static void func(Animal animal1) {
        animal1.eat();
    }


    public static void main(String[] args) {
        Animal animal1=new Dog("xiaohuang",20);
//        Dog dog=(Dog)animal1;//报错的原因是：不是所有的“动物”都是“狗”
//        //把一个大范围给到了一个小范围,强制类型转换一下
//        dog.bark();
//
//        System.out.println("==========================");
//        Animal animal2=new Bird("bird",10);
//        Bird bird=(Bird)animal2;
//        bird.fly();
//        System.out.println("=============================");

        if(animal1 instanceof Bird) {
            Bird bird2=(Bird)animal1;
            bird2.fly();
        } else {
            System.out.println("animal1 instanceof Bird not!");
        }




        //但是向下转型很不安全！

    }







    public static void main3(String[] args) {
        Dog dog=new Dog("小狗",3);
        Bird bird=new Bird("小鸟",3);

        func(dog);
        func(bird);
    }

    public static void main2(String[] args) {
        Animal animal1=new Dog("小黄",10);

        func(new Dog("小黄",10));
    }


    public static int add(int a,int b) {
        return a+b;
    }

    public static int add(int a,int b,int c) {
        return a+b+c;
    }


    public static void main1(String[] args) {
//        Dog dog=new Dog();
//        Animal animal=dog;//把子类对象给父类，这样就叫做向上转型

        Animal animal1=new Dog("小黄",10);
        animal1.eat();
//        animal1.bark();//这里为什么报错？animal中有只有eat，没有bark


    }
}
